import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/pull_down_menu.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/pull_down_menu_controller.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';
import 'package:kq_flutter_widgets_example/resources/theme_colors.dart';

class KqSubPullDownMenuPage extends StatefulWidget {
  const KqSubPullDownMenuPage({super.key});

  @override
  State<KqSubPullDownMenuPage> createState() => _KqSubPullDownMenuPageState();
}

class _KqSubPullDownMenuPageState extends State<KqSubPullDownMenuPage> {
  final _controller = PullDownMenuController();
  List list1 = [
    {'title': 'wode1-', 'titleId': '1'},
    {'title': 'wode2-', 'titleId': '2'},
    {'title': 'wode3-', 'titleId': '3'},
    {'title': 'wode4-', 'titleId': '4'},
    {'title': 'wode5-', 'titleId': '5'},
    {'title': 'wode6-', 'titleId': '6'},
    {'title': 'wode7-', 'titleId': '7'},
    {'title': 'wode8-', 'titleId': '8'},
    {'title': 'quanbu-', 'titleId': null}
  ];

  List list2 = [
    {'title': 'wode21', 'titleId': '1'},
    {'title': 'wode22', 'titleId': '2'},
    {'title': 'wode23', 'titleId': '3'},
    {'title': 'wode24', 'titleId': '4'},
    {'title': 'wode25', 'titleId': '5'},
    {'title': 'wode26', 'titleId': '6'},
    {'title': 'wode27', 'titleId': '7'},
    {'title': 'wode28', 'titleId': '8'},
    {'title': 'quanbu', 'titleId': null}
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: KqHeadBar(
          headTitle: '下拉菜单演示',
          back: () {
            Get.back();
          },
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            PullDownMenu(
              isShowCustomWidget: (menuIndex) {
                if (menuIndex == 1) {
                  return true;
                }
                return false;
              },
              initChosenData: const [
                {'title': '我的-', 'titleId': '1'},
                {'title': '我的2-', 'titleId': '2'},
                {'title': '我的3-', 'titleId': '2'},
              ],
              renderCustomHeaderView: (index, state) {
                if (index == 1) {
                  return KqInkWell(
                      onTap: () {
                        // state.showCustomMenu(index);
                      },
                      child: Container(
                        color: KqThemeColors.bgWhite,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: const [
                            Text('2022-04-23'),
                            Text('~'),
                            Text('2023-04-27'),
                          ],
                        ),
                      ));
                }
                return null;
              },
              headerViewWidth: (index) {
                if (index == 0 || index == 2) {
                  return 100;
                } else {
                  return 200;
                }
              },
              titleRender: (titleData,menuIndex) {
                return titleData['title'];
              },
              menuCustomWidgetRender: (menuIndex, state, menuContext) {
                return Container(
                  width: double.infinity,
                  height: 200,
                  color: KqThemeColors.bgBlue,
                );
              },
              menuDataRender: (menuIndex) {
                if (menuIndex == 0) {
                  return list1;
                }
                return list2;
              },
              menuItemRender: (p0) {
                return p0['title'];
              },
              isUseOverlay: true,
              isDataSame: (p0, p1) {
                if (p0 != null &&
                    p1 != null &&
                    p0['titleId'] == p1['titleId']) {
                  return true;
                } else {
                  return false;
                }
              },
              isSelfControlHeaderData: (index) => false,
              pullDownCallback: (item, menuIndex, menuController) {},
              searchResultCallback: (menuIndex, searchContent) {
                List res = menuIndex == 0 ? list1 : list2;
                List<dynamic> search = [];
                for (dynamic element in res) {
                  String title = element['title']!;
                  if (title.contains(searchContent)) {
                    search.add(element);
                  }
                }
                return search;
              },
            ),
            KqInkWell(
                onTap: () {},
                child: Container(
                  height: 100,
                  color: KqThemeColors.bgBlue,
                ))
          ],
        ));
  }
}
